package com.demo.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.demo.dao.UserDAO;
import com.demo.dao.impl.UserDAOImpl;
import com.demo.entity.User;
import com.demo.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	UserDAO userDAO;

	@Autowired
	UserDAOImpl userDAOImpl;

	@Override
	public User save(User user) {
		return userDAO.save(user);
	}

	@Override
	public void delete(Long id) {
		userDAO.deleteById(id);
	}

	@Override
	public List<User> findAll() {
		return userDAO.findAll();
	}

	@Override
	public User findById(Long id) {
		return userDAO.findById(id).get();
	}

	@Override
	public User findByUsername(String username) {
		return userDAO.findByUsername(username);
	}

	@Override
	public List<User> findByBirthBetween(Date birth, Date birth2) {
		return userDAO.findByBirthBetween(birth, birth2);
	}

	@Override
	public Page<User> findByUsernameLike(String username, Pageable pageable) {
		return userDAO.findByUsernameLike(username, pageable);
	}

	@Override
	public Page<User> search(Pageable pageable, User user) {
		return userDAOImpl.search(pageable, user);
	}

}